require(['../config/requireconfig'],function(config){
	//根据需要添加
	require(['zepto','common/mcommon','swiper'],function($,com,swiper){
		
		com.init();

		var pageLogic = new PageLogic($,com,swiper);
		pageLogic.init();
		
	});
});

var PageLogic = function($,com,Swiper){
	return{
		init:function(){
			var _this = this;
			_this.initData();
			var config = {
				"online":"http://catalogue.acdelco.com.cn/ProdOnlineSearchMB/Index",
				"fix":"/fixGeneral.htm",
				"store":"/storeShop.htm",
				"activity":"/activity.htm",
				"more":"/prodCategory.htm"
			};
			$(".tool").on("click",function(){
				var url = config[$(this).attr("tg")];
				com.utils().windowJump(url);
			})
		},
		initData:function(){
			var _this = this;
			com.ajax({
				url:'/index_data.json',
				success:function(res){
					_this.initBanner(res.data.banners); 
					_this.initCategory(res.data.categoryList); 
				}
			});
		},
		initBanner:function(banners){
			var html = "";
			$(banners).each(function(){
				
				html += '<div class="swiper-slide banner-item">';
				html += '<a href="' + this.targetUrl + '">';
				html += ' <img src="' + com.Config.domain + this.imgUrl + '" >';
				html += '</a>';
				html += '</div>';
				
			});
			$("#bannerCon").html(html);
			
			var swiper = new Swiper('.banner', {
				lazy: true,
			      pagination: {
			        el: '.swiper-pagination',
			      },
		    });
		},
		initCategory:function(categoryList){
			var html = "";
			$(categoryList).each(function(){
				html += '<div class="swiper-slide"> ';
				html += ' <a href="/prodCategory.htm?partsId=' + this.id + '">'
				html += '	<div class="category-img"> ';
				html += '		<img src="' + com.Config.domain + this.imageUrl + '"> ';
				html += '	</div> ';
				html += '	<div class="category-tit"> ';
				html +=          this.categoryName;
				html += '	</div> ';
				html += '	</a> ';
				html += '</div> ';
			});
			$("#categorys").html(html);
			var space = window.lib.flexible.rem2px(0.23);
			var swiper = new Swiper('.categorycon', {
				slidesPerView: 3,
				spaceBetween:space ,
			      navigation: {
			        nextEl: '.btn-next',
			        prevEl: '.btn-prev',
			      },
			});
		}
	}
}